package com.mzy.concurrent;

import java.util.Scanner;
import java.util.ArrayList;

public class RotateSequence {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // 读取n和q
        int n = scanner.nextInt();
        int q = scanner.nextInt();

        // 读取初始序列
        ArrayList<Integer> a = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            a.add(scanner.nextInt());
        }

        // 读取并执行所有操作
        for (int i = 0; i < q; i++) {
            int x = scanner.nextInt() - 1; // 转换为0索引
            int k = scanner.nextInt();

            // 执行rotate操作
            int temp = a.get(x); // 暂存a[x]
            for (int j = x; j < x + k - 1; j++) {
                a.set(j, a.get(j + 1)); // 向左移动元素
            }
            a.set(x + k - 1, temp); // 将暂存的值放回正确位置
        }

        // 输出结果
        for (int num : a) {
            System.out.print(num + " ");
        }
    }
}